<?php
require_once dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'service/AlipayTradeService.php';
require_once dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'buildermodel/AlipayTradeWapPayContentBuilder.php';
require dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'./../config.php';

//商户订单号，商户网站订单系统中唯一订单号，必填
$out_trade_no = rsaDecrypt($_POST['order_no']);

//付款金额，必填
$total_amount = rsaDecrypt($_POST['amount']);

//订单名称，必填
$subject = '小马生鲜';

//订单描述，可空
$body = '订单号：' . $out_trade_no;


$total_amount = 0.01;

//超时时间
$timeout_express="1m";

$payRequestBuilder = new AlipayTradeWapPayContentBuilder();
$payRequestBuilder->setBody($body);
$payRequestBuilder->setSubject($subject);
$payRequestBuilder->setOutTradeNo($out_trade_no);
$payRequestBuilder->setTotalAmount($total_amount);
$payRequestBuilder->setTimeExpress($timeout_express);

$payResponse = new AlipayTradeService($config);
$result=$payResponse->wapPay($payRequestBuilder,$config['return_url'],$config['notify_url']);

/*
 * RSA 公钥解密
 */
function rsaDecrypt($encrypted) {
    $public_key = '-----BEGIN PUBLIC KEY-----  
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3//sR2tXw0wrC2DySx8vNGlqt  
3Y7ldU9+LBLI6e1KS5lfc5jlTGF7KBTSkCHBM3ouEHWqp1ZJ85iJe59aF5gIB2kl  
Bd6h4wrbbHA2XE1sq21ykja/Gqx7/IRia3zQfxGv/qEkyGOx+XALVoOlZqDwh76o  
2n1vP1D+tD3amHsK7QIDAQAB  
-----END PUBLIC KEY-----';

    $pu_key = openssl_pkey_get_public($public_key);

    openssl_public_decrypt(base64_decode($encrypted), $decrypted, $pu_key);

    return $decrypted;
}
?>








